import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Login from '../views/login.vue'
import firstPage from '../views/viewsChild/firstPage.vue'
import pinleiguanli from "../views/viewsChild/pinleiguanli.vue"
import order from "../views/viewsChild/order.vue"
import rule from "../views/viewsChild/rule.vue"
import orderDetail from "../views/viewsChild/viewsSmallChild/orderDetail.vue"
import power from "../views/viewsChild/power.vue"
import user from "../views/viewsChild/user.vue"
import specAttr from "../views/viewsChild/specAttr.vue"
import goods from "../views/viewsChild/goods.vue"

Vue.use(VueRouter)

const router = new VueRouter({
  routes: [{
      path: '/home',
      name: 'Home',
      component: Home,
      children: [{
          path: '/firstPage',
          component: firstPage,
        }, {
          path: '/pinleiguanli',
          component: pinleiguanli,
        }, {
          path: '/order',
          name: 'Name',
          component: order,
        },
        {
          path: '/rule',
          name: 'rule',
          component: rule
        },
        {
          path: '/orderDetail',
          name: 'orderDetail',
          component: orderDetail,
        },
        {
          path: '/power',
          name: 'power',
          component: power
        },
        {
          path: '/user',
          name: 'user',
          component: user
        },
        {
          path: '/specAttr',
          name: 'specAttr',
          component: specAttr
        },
        {
          path:'/goods',
          name: 'goods',
          component: goods
        }

      ]
    },
    {
      path: '/about',
      name: 'About',
      component: () => import( /* webpackChunkName: "about" */ '../views/about.vue')
    },
    {
      path: '/',
      name: 'Login',
      component: Login
    },

  ]

})

router.beforeEach((to, from, next) => {
  let token = localStorage.getItem('token')
  if (!token && to.path !== '/') {
    next("/")
  }
  if (token && to.path == '/') {
    if (!window.confirm('是否退出登录')) {
      next(from.path)
    }
  }
  next()
})



export default router